animate: function() {
  <%-
    animation = []
    animation << "remove_todo" if update_needs_to_remove_todo_from_container
    if replace_with_updated_todo
      animation << "replace_todo"
    elsif append_updated_todo
      animation << ( update_needs_to_add_new_container ? "insert_new_container_with_updated_todo" : "add_to_existing_container")
    end
    animation << "hide_container" if update_needs_to_hide_container
    animation << "highlight_updated_todo"
    animation << "update_empty_container" if source_view_is_one_of(:tag, :todo, :deferred, :project, :context)
    animation << "update_predecessors"
  -%>
  TracksPages.page_inform('<%=escape_javascript @status_message%>');
  TracksPages.set_page_badge(<%= @down_count %>);
  <%= render_animation(animation, object_name) %>
},
remove_todo: function(next_steps) {
  $('#<%= dom_id(@todo) %>').fadeOut(400, function() {
    $('#<%= dom_id(@todo) %>').remove();
    <% if source_view_is :calendar
      # in calendar view it is possible to have a todo on the page twice
    -%>
      $('#<%= dom_id(@todo) %>').remove();
    <% end -%>
    <%= show_empty_message_in_source_container -%>
    next_steps.go();
  });
},
add_to_existing_container: function(next_steps) {
  var container = $('#<%= item_container_id(@todo) %>_items');
  container.append(<%=object_name%>.html_for_todo());
  TracksPages.sort_container(container);
  <% if source_view_is_one_of(:calendar) -%>
    next_steps.go();
    <% if (@target_context_count==1) || ( (@todo.deferred? || @todo.pending?) && @remaining_deferred_or_pending_count == 1) -%>
      $("#<%=  empty_container_msg_div_id %>").slideUp(100);
    <% end -%>
  <% else -%>
    <% unless (@todo_hidden_state_changed && @todo.hidden?) || @todo_was_deferred_from_active_state -%>
      $('#<%= item_container_id(@todo) %>').fadeIn(500, function() {
        next_steps.go();
        <% if @target_context_count==1 -%>
          $("#<%=  empty_container_msg_div_id %>").slideUp(100);
        <% end -%>
      });
    <% else -%>
      next_steps.go();
      <% if (@target_context_count==1) ||
        ( (@todo.deferred? || @todo.pending?) && @remaining_deferred_or_pending_count == 1) ||
        ( @todo.hidden?                       && @remaining_hidden_count == 1)
      -%>
        $("#<%=  empty_container_msg_div_id %>").slideUp(100);
      <% end -%>
    <% end -%>
  <% end -%>
},
replace_todo: function(next_steps) {
  $('#<%= dom_id(@todo) %>').replaceWith(<%=object_name%>.html_for_todo());
  TracksPages.sort_container($('#<%= item_container_id(@todo) %>_items'));
  next_steps.go();
},
hide_container: function(next_steps) {
  $('#<%= item_container_id(@original_item) %>').fadeOut(400, function(){ next_steps.go(); });
  <%= "$('#deferred_pending_container_empty-nd').slideDown(400);".html_safe if source_view_is(:deferred) && @down_count == 0 %>
},
highlight_updated_todo: function(next_steps) {
  $('#<%= dom_id(@todo)%>').effect('highlight', {}, 2000, function(){ });
  next_steps.go();
},
update_empty_container: function(next_steps) {
  <% if should_show_empty_container -%>
    $('div#no_todos_in_view').slideDown(400, function(){ next_steps.go(); });
  <% else -%>
    $('div#no_todos_in_view').fadeOut(100, function(){ next_steps.go(); });
  <% end -%>
},
update_badge_count: function() {
  <%
    count = source_view_is(:context) ? @remaining_in_context : @down_count
    count = @project_changed ? @remaining_undone_in_project : count
  -%>
  TracksPages.set_page_badge(<%= count %>);
},
insert_new_container_with_updated_todo: function(next_steps) {
  $('#display_box').prepend(<%=object_name%>.html_for_new_container());
  $('#<%= item_container_id(@todo) %>').fadeIn(500, function() { next_steps.go(); });
},
html_for_todo: function() {
  return "<%= escape_javascript(render(:partial => @todo, :locals => { :parent_container_type => parent_container_type })) %>";
},
html_for_new_container: function() {
  return "<%= ( @new_context_created || @new_project_created ) ? escape_javascript(render(:partial => @new_container, :locals => { :settings => {:collapsible => true }})) : "" %>";
},
update_predecessors: function(next_steps) {
  <%=object_name%>.regenerate_predecessor_family();
  <% if @removed_predecessors
    @removed_predecessors.each do |p| -%>
      if ($('#<%=item_container_id(p)%>')) {
        $('#<%=dom_id(p)%>').html('<%=escape_javascript(render(:partial => p, :locals => { :settings => {:parent_container_type => parent_container_type }}))%>');
      }
    <% end -%>
  <% end -%>
  next_steps.go();
},
regenerate_predecessor_family: function() {
  <%
    parents = @todo.predecessors.to_a
    until parents.empty?
      parent = parents.pop
      parents += parent.predecessors
  -%>
      $('#<%= dom_id(parent) %>').html("<%= escape_javascript(render(:partial => parent, :locals => { :settings => {:parent_container_type => parent_container_type }})) %>");
  <%
    end
  -%>
}
